import {A_soldier} from "./models/a_soldier";
import {
    a_soldier_actionproperty,
    a_tank_actionproperty,
    armylevels,
    tank_actions,
    truck_actionproperty
} from "./commdata";
import {
    allobjects,
    armylimit,
    enemyenablelimit,
    GetEnemys,
    getXY,
    playerteam, ReleaseAllDestroidResource,
    ReleaseResource,
    ReStortObjects
} from "./comm";
import {Point} from "./models/point";
import {Tank} from "./models/tank";
import {army} from "./models/army";
import {Building} from "./models/building";
import {Truck} from "./models/truck";
import {Obj_class} from "./models/obj_class";
import {Basebio} from "./models/basebio";
import {Missile} from "./models/missile";

const pt:HTMLCanvasElement = document.getElementById("paintP") as HTMLCanvasElement;
const ptctx: CanvasRenderingContext2D | null = pt.getContext("2d");
const btnref:HTMLInputElement=document.getElementById("btnref") as HTMLInputElement;
const adio=new Audio();

let enemyinfo=armylevels[3];
let mousepoint = new Point();

let enemylivesoldiers:number=0;
let enemylivetanks:number=0;
let enemylivetrucks:number=0;

let Tanks=new Array();
let buildobjs=new Array(); //建筑物集合
let isInPlane:boolean=false;
let isSelectTank:boolean=false;
let isBuildSelect:boolean=false;
let isBoomSelect:boolean=false;
let isUpCount:boolean=false;
let isrect:boolean=false;

let Startflag:boolean=false;
//let enemyStartdeley:number=100; //延迟设置十秒钟
let Startindex:number=100; //延迟即使 600


let currentArmycount:number=0; //我方实际单位数
let killsoldiersenemycount:number=0 //杀敌人数
let killtruckenemycount:number=0 //杀敌车辆数
let killtankenemycount:number=0 //杀敌车辆数
let lostcount:number=0; //我方损失
let canfighters:number=20; //可以参加战斗的作战单位
let missilecount=3;
let enemycount=0;  //当前屏幕支撑的地方作战单位数量
let id=0;

 //所有对象用于显示

let mouseMoveTank:Tank=new Tank(
    "",100,100,0,0,0,0,0,0
);

let mouseMoveBuild:Building=new Building("movebuild",0,0,
    "buildtank",1000,100,0,0,0);

let armytank:army=new army("tank",0,0);

let missile:Missile=new Missile("missile");

let building:Building=new Building("",0,0,"buildtank",1000,1000,80,45,0);

let ecount:number=0;
let truckecount:number=0;
let tankecount:number=0;

const loaderdatas=()=>{
    ReleaseAllDestroidResource();
    while (allobjects.length<enemyenablelimit) {
        let tmpflag = Math.floor(Math.random() * (500 - 0 + 1)) + 0;
       if (tmpflag > 497) {

           if(truckecount<enemyinfo.trucks) {
               //卡车
               let temptruck = new Truck(
                   "truck" + (id).toString(), 100, 100, 1000 - truck_actionproperty.ratewidth,
                   Math.floor(Math.random() * (500 - truck_actionproperty.rateheight)) + 1, 10, 0, 1, 3
               );
               temptruck.fun = "l";
               temptruck.shootrange = 250 + Math.floor(Math.random() * (50) + 0);
               temptruck.searchrange = 300;
               temptruck.enable = false;
               temptruck.deadfinish = false;
               allobjects.push({
                   clsname: "Truck",
                   objval: temptruck,
                   x: temptruck.x,
                   y: temptruck.y
               })
               truckecount = truckecount + 1;
               id = id + 1;
           }
        } else {
           if(ecount<enemyinfo.soldiers) {
               //士兵
               let asoilder = new A_soldier("soilder" + (id).toString(), 20, 100, 1000 - a_soldier_actionproperty.ratewidth,
                   Math.floor(Math.random() * (500 - a_soldier_actionproperty.rateheight)) + 1);
               asoilder.fun = "l";
               asoilder.shootrange = 200 + Math.floor(Math.random() * (50) + 0);
               asoilder.searchrange = 250;
               asoilder.enable = false;
               asoilder.team = 1;
               asoilder.deadfinish = false;
               allobjects.push({
                   clsname: "A_soldier",
                   objval: asoilder,
                   x: asoilder.x,
                   y: asoilder.y
               })
               ecount = ecount + 1;
               id = id + 1;
           }
        }
    }
    ReStortObjects(allobjects);
}

let stageimage = new Image();
stageimage.src = require("./images/res_bg.png");
let l_x=0;

//鼠标操作按下
pt.onmousedown = function (e) {
    if (e.button.toString() === "0") {
        // if (fighter.ammunition > 0) {
        //     //左键操作
        //     fighter.isfire = true;
        //     adio.src =shoot1; //require("./sound/shoot1.wav");
        // }

        let pp = getXY(pt, e);
        if(isInPlane==true) {
            if (isSelectTank == true) {
                if (isrect == false) {
                    if(currentArmycount<armylimit &&
                        canfighters>0) {
                        let temptank = new Tank("tank"+(Tanks.length+1).toString(), 300, 300, pp.x - 10, pp.y - 10, 10, 300,0,0);
                        temptank.deadfinish=false;
                        temptank.isstart=true;
                        temptank.enable=true;
                        //Tanks.push(temptank);
                        allobjects.push({
                            clsname:"Tank",
                            objval:temptank,
                            x:temptank.x,
                            y:temptank.y
                        });
                        //排序
                        //ReStortObjects(allobjects);
                        currentArmycount=currentArmycount+1;
                        canfighters=canfighters-1;
                    }
                    else
                    {
                        if(currentArmycount>=armylimit)
                            isUpCount=true;
                        isSelectTank=false;
                        isrect=false;
                    }
                }
            }

            if(isBuildSelect==true)
            {
                if (isrect == false) {
                    let temptankbuild:Building = new Building("tt", pp.x - mouseMoveBuild.img.width/3,
                        pp.y -  mouseMoveBuild.img.height/3,
                        "buildtank", 2000,2000,0, 0,0);
                    buildobjs.push(temptankbuild);
                    isBuildSelect=false;
                }
            }

            if(isBoomSelect==true){
                missile.destroyed(allobjects.filter(r=>r.objval.team!=playerteam));
                isBoomSelect=false;
                missilecount=missilecount-1;
            }
        }
        else {
            if (pp.x > armytank.x && pp.x < armytank.x + armytank.ratewidth) {
                if (pp.y > armytank.y && pp.x < armytank.y + armytank.rateheight) {
                    armytank.isSelect = true;
                    isSelectTank = true;
                    isBuildSelect=false;
                }
            } else
            {
                armytank.isSelect = false;
                isSelectTank = false;
            }

            if (pp.x > building.x && pp.x < building.x + building.ratewidth) {
                if (pp.y > building.y && pp.x < building.y + building.rateheight) {
                    building.isSelect = true;
                    isSelectTank = false;
                    isBuildSelect=true;
                }
            } else
            {
                building.isSelect = false;
                isBuildSelect=false;
            }

            //炸弹选中
            if (pp.x > missile.x && pp.x < missile.x + missile.ratewidth) {
                if (pp.y > missile.y && pp.x < missile.y + missile.rateheight) {
                    if(missilecount>0) {
                        missile.isSelect = true;
                        isSelectTank = false;
                        isBuildSelect = false;
                        isBoomSelect = true;
                    }
                }
            } else
            {
                missile.isSelect = false;
                isBoomSelect=false;
            }

        }
    }
    else if (e.button.toString() === "2") {
        //右键操作
        //autoreloadammou();
        isSelectTank=false;
        isBuildSelect=false;
        isBoomSelect=false;
        armytank.isSelect=false;

    }
}
//鼠标抬起
pt.onmouseup = function (e) {
    //fighter.isfire = false;
    //adio.pause();
    isUpCount=false;
}

mouseMoveTank.enable=true;
mouseMoveTank.deadfinish=false;
mouseMoveTank.isstart=true;

pt.onmousemove = function (e) {
    let pp = getXY(pt, e);
    if (pp.x < (pt.width - 50) &&
        pp.y<(pt.height-100-50)
    ) {
        isInPlane=true;
        mousepoint = pp;
        if(isSelectTank==true) {
            mouseMoveTank.x = pp.x - 10;
            mouseMoveTank.y = pp.y - 10;
        }
        else if(isBuildSelect==true) {
            mouseMoveBuild.x = pp.x - mouseMoveBuild.img.width/3;
            mouseMoveBuild.y = pp.y -  mouseMoveBuild.img.height/3;
        }
        else if(isBoomSelect==true)
        {
            missile.destoried_x=pp.x;
            missile.destoried_y=pp.y;
        }
    }
    else
    {
        isInPlane=false;
    }
}

var timer = setInterval(function () {
    pt.width = 1000;
    pt.height = 600;
    armytank.x=80;
    armytank.y=510;
    missile.x=230;
    missile.y=510;

    building.x=410;
    building.y=515;
    mouseMoveTank.fun="ur";
    mouseMoveTank.deadfinish=false;
    //pt.style.cursor = "url("+ cus1+") 20 20,auto"
    //pt.style.cursor ="crosshair";  //require("./images/cus1.png");
    loaderdatas();
    if (ptctx != null) {
        ptctx.beginPath();
        ptctx.clearRect(0, 0, pt.width, pt.height);
        ptctx.rect(0, 0, pt.width - 1, pt.height - 1);
        ptctx.stroke();

        ptctx.rect(0, 500, pt.width - 1, 100);
        ptctx.stroke();

        // ptctx?.drawImage(stageimage, 0,
        //     0, pt.width, pt.height - 100);

        if (Startindex > 0) {
            Startindex = Startindex - 1;
        } else {
            Startflag = true;
        }
        enemylivesoldiers = 0;
        enemylivetrucks = 0;
        currentArmycount = 0;
        for (let i = 0; i < allobjects.length; i++) {
            let tempobj: Obj_class = allobjects[i];
            let tempbasobj: Basebio = tempobj.objval;
            if (tempobj.clsname == "A_soldier") {
                let tempsoldier = tempobj.objval;
                if (tempsoldier.team != playerteam) {
                    if (Startflag == true) {
                        if (tempsoldier.live > 0) {
                            if (tempsoldier.isstart == false) {
                                if (Math.floor(Math.random() * (500)) == 5) {
                                    tempsoldier.isstart = true;
                                    tempsoldier.fun = "l";
                                }
                            }
                            if (tempsoldier.enable == false) {
                                enemycount = enemycount + 1;
                                tempsoldier.enable = true;
                            }
                            let tempobjs = GetEnemys(allobjects, tempsoldier.team);
                            tempsoldier.setSoldierfire(tempobjs);
                            enemylivesoldiers = enemylivesoldiers + 1;

                            if (tempsoldier.x < -tempsoldier.ratewidth) {
                                tempsoldier.x = pt.width - a_soldier_actionproperty.ratewidth;
                            }

                        } else {
                            if (tempsoldier.issumflag == false) {
                                tempsoldier.issumflag = true;
                                killsoldiersenemycount = killsoldiersenemycount + 1;
                            }
                            if (tempsoldier.deadfinish == true) {
                                tempsoldier.enable = false;
                                enemycount = enemycount - 1;
                            }

                        }
                    }
                } else {
                    tempsoldier.isstart = Startflag
                    if (tempsoldier.live > 0) {
                        currentArmycount = currentArmycount + 1;
                        let tempobjs = GetEnemys(allobjects, tempsoldier.team);
                        tempsoldier.setSoldierfire(tempobjs);
                    } else {
                        if (tempsoldier.issumflag == false) {
                            lostcount = lostcount + 1;
                            tempsoldier.issumflag = true;
                        }
                    }
                }
            } else if (tempobj.clsname == "Truck") {
                let tempTruck: Truck = tempobj.objval;
                if (tempTruck.team != playerteam) {
                    if (Startflag == true) {
                        if (tempTruck.live > 0) {
                            if (tempTruck.isstart == false) {
                                if (Math.floor(Math.random() * (10)) == 5) {
                                    tempTruck.isstart = true;
                                    tempTruck.fun = "l";
                                }
                            }

                            if (tempTruck.enable == false) {
                                enemycount = enemycount + 1;
                                tempTruck.enable = true;
                            }
                            enemylivetrucks = enemylivetrucks + 1;
                            if (tempTruck.x < -tempTruck.ratewidth) {
                                tempTruck.x = pt.width - truck_actionproperty.ratewidth;
                            }
                            let tempobjs = GetEnemys(allobjects, tempTruck.team);
                            tempTruck.setTruckfire(tempobjs);
                        } else {
                            if (tempTruck.issumflag == false) {
                                tempTruck.issumflag = true;
                                killtruckenemycount = killtruckenemycount + 1;
                            }
                        }
                    }
                } else {
                    tempTruck.isstart = Startflag;
                    if (tempTruck.live > 0) {
                        currentArmycount = currentArmycount + 1;
                        let tempobjs = GetEnemys(allobjects, tempTruck.team);
                        tempTruck.setTruckfire(tempobjs);
                    } else {
                        if (tempTruck.issumflag == false) {
                            lostcount = lostcount + 1;
                            tempTruck.issumflag = true;
                        }
                    }
                }
            } else if (tempobj.clsname == "Tank") {
                let tempTank: Tank = tempobj.objval;
                if (tempTank.team != playerteam) {
                    if (Startflag == true) {
                        if (tempTank.live > 0) {
                            if (tempTank.enable == false) {
                                enemycount = enemycount + 1;
                                tempTank.enable = true;
                            }
                            enemylivetanks = enemylivetanks + 1;
                            let tempobjs = GetEnemys(allobjects, tempTank.team);
                            tempTank.setTankfire(tempobjs);
                            if (tempTank.x < -tempTank.ratewidth) {
                                tempTank.x = pt.width - a_tank_actionproperty.ratewidth;
                            }
                        } else {
                            if (tempTank.issumflag == false) {
                                tempTank.issumflag = true;
                                killtankenemycount = killtankenemycount + 1;
                            }

                        }
                    }
                } else {
                    tempTank.isstart = Startflag;
                    if (tempTank.live > 0) {
                        currentArmycount = currentArmycount + 1;
                        let tempobjs = GetEnemys(allobjects, tempTank.team);
                        tempTank.setTankfire(tempobjs);
                    } else {
                        if (tempTank.issumflag == false) {
                            lostcount = lostcount + 1;
                            tempTank.issumflag = true;
                        }
                    }
                }
            }

            if (tempbasobj.deadfinish == true) {
                tempbasobj.enable = false;
                enemycount = enemycount - 1;
            }
        }

        for (let i = 0; i < buildobjs.length; i++) {
            if (buildobjs[i].live > 0) {
                buildobjs[i].actiondraw(ptctx);
                if (buildobjs[i].isCompleteProduce == true) {
                    buildobjs[i].isCompleteProduce = false;
                    buildobjs[i].produceindex = 0;
                    canfighters = canfighters + 1;
                }
            }
        }

        drawobjects(ptctx);
        //鼠标
        if (isSelectTank == true) {
            isrect = false;
            for (let i = 0; i < Tanks.length; i++) {
                if (mouseMoveTank.x > Tanks[i].x && mouseMoveTank.x < Tanks[i].x + Tanks[i].ratewidth) {
                    if (mouseMoveTank.y > Tanks[i].y && mouseMoveTank.y < Tanks[i].y + Tanks[i].rateheight) {
                        isrect = true;
                        break;
                    }
                }
            }

            for (let i = 0; i < buildobjs.length; i++) {
                if (mouseMoveTank.x > buildobjs[i].x && mouseMoveTank.x < buildobjs[i].x + buildobjs[i].ratewidth) {
                    if (mouseMoveTank.y > buildobjs[i].y && mouseMoveTank.y < buildobjs[i].y + buildobjs[i].rateheight) {
                        isrect = true;
                        break;
                    }
                }
            }

            if (isInPlane == true) {
                if (isrect == true) {
                    ptctx.globalAlpha = 0.4;
                    ptctx.fillStyle = "red";
                    ptctx.fillRect(mouseMoveTank.x, mouseMoveTank.y, mouseMoveTank.ratewidth, mouseMoveTank.rateheight);
                    ptctx.strokeRect(mouseMoveTank.x, mouseMoveTank.y, mouseMoveTank.ratewidth, mouseMoveTank.rateheight)
                    mouseMoveTank.actiondraw(ptctx, pt.width, pt.height - a_soldier_actionproperty.rateheight);
                    ptctx.globalAlpha = 1;
                } else {
                    mouseMoveTank.actiondraw(ptctx, pt.width, pt.height - a_soldier_actionproperty.rateheight);
                }
            }
        }

         if (isBoomSelect == true) {
             missile.missileDestroyDraw(ptctx,missile.destoried_x,missile.destoried_y);
         }

        if (isBuildSelect == true) {
            isrect = false;
            for (let i = 0; i < Tanks.length; i++) {
                if (mouseMoveBuild.x > Tanks[i].x && mouseMoveBuild.x < Tanks[i].x + Tanks[i].ratewidth) {
                    if (mouseMoveBuild.y > Tanks[i].y && mouseMoveBuild.y < Tanks[i].y + Tanks[i].rateheight) {
                        isrect = true;
                        break;
                    }
                }
            }

            for (let i = 0; i < buildobjs.length; i++) {
                if (mouseMoveBuild.x > buildobjs[i].x && mouseMoveBuild.x < buildobjs[i].x + buildobjs[i].ratewidth) {
                    if (mouseMoveBuild.y > buildobjs[i].y && mouseMoveBuild.y < buildobjs[i].y + buildobjs[i].rateheight) {
                        isrect = true;
                        break;
                    }
                }
            }

            if (isInPlane == true) {
                if (isBuildSelect == true) {
                    if (isrect == true) {
                        ptctx.globalAlpha = 0.4;
                        ptctx.fillStyle = "red";
                        ptctx.fillRect(mouseMoveBuild.x, mouseMoveBuild.y, mouseMoveBuild.ratewidth, mouseMoveBuild.rateheight);
                        ptctx.strokeRect(mouseMoveBuild.x, mouseMoveBuild.y, mouseMoveBuild.ratewidth, mouseMoveBuild.rateheight)
                        mouseMoveBuild.actiondraw(ptctx);
                        ptctx.globalAlpha = 1;
                    } else {
                        mouseMoveBuild.actiondraw(ptctx);
                    }
                }
            }
        }
        drawinfo(ptctx);
    }
}, 100);

const drawinfo=(ptctx: any)=>{
    ptctx.font = "oblique small-caps bold 12px Arial";
    ptctx.fillStyle = "green";
    ptctx.fillText("单位类型:", 10, 520);
    ptctx.rect(70, 508, 200, 82);
    ptctx.stroke();

    armytank.drawarmy(ptctx);

    missile.missiledraw(ptctx);

    ptctx.font = "oblique small-caps bold 12px Arial";
    ptctx.fillStyle = "blue";
    ptctx.fillText("人口数量："+currentArmycount.toString()+"/"+armylimit.toString(), 290, 520);
    ptctx.fillText("可出战单位："+canfighters.toString(), 290, 535);
    ptctx.fillText("歼敌："+(killsoldiersenemycount+killtruckenemycount+killtankenemycount).toString(), 290, 550);
    ptctx.fillText("损失："+lostcount.toString(), 290, 565);


    ptctx.fillText("数量:"+missilecount.toString(), missile.x, missile.y+missile.rateheight+15);


    if( isUpCount==true) {
        ptctx.font = "oblique small-caps bold 35px Arial";
        ptctx.fillStyle = "yellow";
        ptctx.fillText("已经到达人口上限", pt.width / 2 - 150, pt.height / 2);
    }
    ptctx.stroke();

    if(Startindex<60 && Startflag==false)
    {
        ptctx.font = "oblique small-caps bold 35px Arial";
        ptctx.fillStyle = "yellow";
        ptctx.fillText("倒计时："+(Startindex*100/1000).toString(), pt.width / 2 - 150, pt.height / 2);
    }

    //建筑单位
    ptctx.font = "oblique small-caps bold 12px Arial";
    ptctx.fillStyle = "green";
    ptctx.fillText("单位类型:", 10, 520);
    ptctx.rect(400, 508, 300, 82);
    ptctx.stroke();

    //敌方信息
    ptctx.font = "oblique small-caps bold 12px Arial";
    ptctx.fillStyle = "red";
    ptctx.fillText("敌方信息:", 710, 520);
    ptctx.fillText("部队:"+enemyinfo.type, 710, 535);
    ptctx.fillText("士兵:"+(enemyinfo.soldiers-killsoldiersenemycount).toString()+"/"+enemyinfo.soldiers.toString(), 710, 550);
    ptctx.fillText("车辆:"+(enemyinfo.trucks-killtruckenemycount).toString()+"/"+enemyinfo.trucks.toString(), 710, 565);
    ptctx.fillText("坦克:"+enemylivetanks.toString()+"/"+enemyinfo.tanks.toString(), 710, 580);
    ptctx.stroke();

    //ptctx.drawImage(building.img,0,0,building.img.width,building.img.height,410,515,building.ratewidth,building.rateheight);
    building.builddraw(ptctx);
    ptctx.stroke();

    //ReleaseAllDestroidResource();
}

//绘制对象
const drawobjects=(ptctx: any)=> {

    //死亡对象
    for (let i = 0; i < allobjects.length; i++) {
        let Tempobj:Obj_class = allobjects[i];
        if (Tempobj.clsname == "A_soldier") {
            let tempsoldier: A_soldier = Tempobj.objval;
            if(tempsoldier.team==playerteam)
            {
                if (tempsoldier.live <= 0 ) {
                    tempsoldier.deaddraw(ptctx);
                }
            }
            else
            {
                if( tempsoldier.isstart == true &&
                    tempsoldier.enable == true) {
                    if (tempsoldier.live <= 0) {
                        tempsoldier.deaddraw(ptctx);
                    }
                }
            }
        }
        else if (Tempobj.clsname == "Truck") {
            let tempTruck: Truck = Tempobj.objval;
            if(tempTruck.team == playerteam)
            {
                if (tempTruck.live <= 0) {

                    tempTruck.deaddraw(ptctx);
                }
            }
            else {
                if( tempTruck.isstart == true &&
                    tempTruck.enable == true){

                    if(tempTruck.live<=0)
                    {
                        tempTruck.deaddraw(ptctx);
                    }
                }
            }
        }
        else if (Tempobj.clsname == "Tank") {
            let tempTank: Tank = Tempobj.objval;
            if (tempTank.team == playerteam) {
                if (tempTank.live <= 0) {
                    tempTank.deaddraw(ptctx);
                }
            }
            else
            {
                if(tempTank.isstart == true &&
                    tempTank.enable == true) {
                    if (tempTank.live <= 0) {
                        tempTank.deaddraw(ptctx);
                    }
                }
            }
        }
    }

    //刷新阴影
    for (let i = 0; i < allobjects.length; i++) {
        if (allobjects[i].clsname == "A_soldier") {
            let tempsoldier: A_soldier = allobjects[i].objval;
            if (tempsoldier.enable == true &&
                tempsoldier.isstart == true)
                tempsoldier.drawshowdo(ptctx);

        } else if (allobjects[i].clsname == "Truck") {
            let tempTruck: Truck = allobjects[i].objval;
            if (tempTruck.enable == true &&
                tempTruck.isstart == true)
                tempTruck.drawshowdo(ptctx);
        } else if (allobjects[i].clsname == "Tank") {
            let tempTank: Tank = allobjects[i].objval;
            if (tempTank.enable == true) {
            }
        }
    }

    //刷新活着的对象
    for (let i = 0; i < allobjects.length; i++) {
        let Tempobj:Obj_class = allobjects[i];
        if (Tempobj.clsname == "A_soldier") {
            let tempsoldier: A_soldier = Tempobj.objval;
            if(tempsoldier.team==playerteam)
            {
                if (tempsoldier.live > 0 ) {
                    tempsoldier.actiondraw(ptctx, pt.width, pt.height - a_soldier_actionproperty.rateheight)
                }
            }
            else
            {
                if( tempsoldier.isstart == true &&
                    tempsoldier.enable == true) {
                    if (tempsoldier.live > 0) {
                        tempsoldier.actiondraw(ptctx, pt.width, pt.height - a_soldier_actionproperty.rateheight)
                    }
                }
            }
        }
        else if (Tempobj.clsname == "Truck") {
            let tempTruck: Truck = Tempobj.objval;
            if(tempTruck.team == playerteam)
            {
                if (tempTruck.live > 0) {
                    tempTruck.actiondraw(ptctx, pt.width, pt.height - truck_actionproperty.rateheight);
                }
            }
            else {
                if( tempTruck.isstart == true &&
                    tempTruck.enable == true){
                    if(tempTruck.live>0)
                    {
                        tempTruck.actiondraw(ptctx, pt.width, pt.height - truck_actionproperty.rateheight);
                    }
                }
            }
        }
        else if (Tempobj.clsname == "Tank") {
            let tempTank: Tank = Tempobj.objval;
            if (tempTank.team == playerteam) {
                if (tempTank.live > 0) {
                    tempTank.actiondraw(ptctx, pt.width, pt.height - a_tank_actionproperty.rateheight);
                }
            }
            else
            {
                if(tempTank.isstart == true &&
                    tempTank.enable == true) {
                    if (tempTank.live > 0) {
                        tempTank.actiondraw(ptctx, pt.width, pt.height - a_tank_actionproperty.rateheight);
                    }
                }
            }
        }
    }

    //刷新文字信息
    for(let i=0;i<allobjects.length;i++) {
        if (allobjects[i].clsname == "A_soldier") {
            let tempsoldier: A_soldier = allobjects[i].objval;
            if(tempsoldier.team==playerteam) {
                if (tempsoldier.live > 0) {
                    //tempsoldier.drawinfo(ptctx);
                }
            }
            else
            {
                if (tempsoldier.live > 0 &&
                    tempsoldier.isstart==true &&
                    tempsoldier.enable==true
                ){
                   // tempsoldier.drawinfo(ptctx);
                }
            }
        } else if (allobjects[i].clsname == "Truck") {

        } else if (allobjects[i].clsname == "Tank") {
            let tempTank: Tank = allobjects[i].objval;
            if(tempTank.team==playerteam) {
                if (tempTank.live > 0) {
                    tempTank.drawinfo(ptctx);
                }
            }
            else
            {
                if (tempTank.live > 0 &&
                    tempTank.isstart==true &&
                    tempTank.enable==true
                ) {
                    tempTank.drawinfo(ptctx);
                }
            }
        }
    }
}